<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.12.0"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>NeuZephyr: nz::graph Namespace Reference</title>
<link rel="icon" href="NZ_logo2.png" type="image/x-icon" />
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectlogo"><img alt="Logo" src="NZ_logo2.png"/></td>
  <td id="projectalign">
   <div id="projectname">NeuZephyr
   </div>
   <div id="projectbrief">Simple DL Framework</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.12.0 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() { codefold.init(0); });
/* @license-end */
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li class="current"><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="namespaces.html"><span>Namespace&#160;List</span></a></li>
      <li><a href="namespacemembers.html"><span>Namespace&#160;Members</span></a></li>
    </ul>
  </div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function(){ initResizable(false); });
/* @license-end */
</script>
<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><b>nz</b></li><li class="navelem"><a class="el" href="namespacenz_1_1graph.html">graph</a></li>  </ul>
</div>
</div><!-- top -->
<div id="doc-content">
<div class="header">
  <div class="summary">
<a href="#nested-classes">Classes</a> &#124;
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle"><div class="title">nz::graph Namespace Reference</div></div>
</div><!--header-->
<div class="contents">

<p>Contains classes and functions for managing and executing computation graphs in deep learning workflows.  
<a href="#details">More...</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="nested-classes" name="nested-classes"></a>
Classes</h2></td></tr>
<tr class="memitem:"><td class="memItemLeft" align="right" valign="top">class &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classnz_1_1graph_1_1_compute_graph.html">ComputeGraph</a></td></tr>
<tr class="memdesc:"><td class="mdescLeft">&#160;</td><td class="mdescRight">Represents a computational graph, which manages nodes and the computation flow.  <a href="classnz_1_1graph_1_1_compute_graph.html#details">More...</a><br /></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:ae69fc8042f6dedeff293ab270f9c2baa" id="r_ae69fc8042f6dedeff293ab270f9c2baa"><td class="memItemLeft" align="right" valign="top">std::ostream &amp;&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#ae69fc8042f6dedeff293ab270f9c2baa">operator&lt;&lt;</a> (std::ostream &amp;os, <a class="el" href="classnz_1_1graph_1_1_compute_graph.html">ComputeGraph</a> &amp;graph)</td></tr>
<tr class="memdesc:ae69fc8042f6dedeff293ab270f9c2baa"><td class="mdescLeft">&#160;</td><td class="mdescRight">Overloads the stream insertion operator to print the details of the computational graph.  <br /></td></tr>
<tr class="separator:ae69fc8042f6dedeff293ab270f9c2baa"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a3c6187d695022b05df227d913ac89d91" id="r_a3c6187d695022b05df227d913ac89d91"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a3c6187d695022b05df227d913ac89d91">CreateNode</a> (<a class="el" href="classnz_1_1graph_1_1_compute_graph.html">ComputeGraph</a> *graph, const std::string &amp;type, const std::string &amp;name, std::vector&lt; int &gt; pre, const <a class="el" href="classnz_1_1data_1_1_dimension.html">Tensor::shape_type</a> &amp;shape, float *data, const bool requires_grad, float *grad)</td></tr>
<tr class="memdesc:a3c6187d695022b05df227d913ac89d91"><td class="mdescLeft">&#160;</td><td class="mdescRight">Creates and adds a node to the computational graph based on the specified type.  <br /></td></tr>
<tr class="separator:a3c6187d695022b05df227d913ac89d91"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>Contains classes and functions for managing and executing computation graphs in deep learning workflows. </p>
<p>The <code><a class="el" href="namespacenz_1_1graph.html" title="Contains classes and functions for managing and executing computation graphs in deep learning workflo...">nz::graph</a></code> namespace provides essential tools for creating, managing, and executing computation graphs in deep learning models. It facilitates the construction of neural networks, supports forward and backward propagation, and allows for gradient computation and optimization steps. This namespace is integral to the workflow of deep learning frameworks, ensuring efficient execution on GPU devices.</p>
<p>Key components within this namespace include:</p><ul>
<li><b><a class="el" href="classnz_1_1graph_1_1_compute_graph.html" title="Represents a computational graph, which manages nodes and the computation flow.">ComputeGraph</a></b>: A class representing the computation graph that holds nodes and manages data flow between them.</li>
<li><b>Nodes</b>: A collection of different computational nodes, such as layers (e.g., AddNode, MatMulNode) and activation functions (e.g., ReLUNode, SigmoidNode).</li>
<li><b>Optimizers</b>: Utilities for updating the parameters of the nodes (e.g., through stochastic gradient descent).</li>
<li><b>Forward and Backward Propagation</b>: Functions to propagate inputs through the network and compute gradients for model optimization.</li>
<li><b>Graph Persistence</b>: Methods to save and load the computation graph, preserving model state.</li>
</ul>
<p>The <code><a class="el" href="namespacenz_1_1graph.html" title="Contains classes and functions for managing and executing computation graphs in deep learning workflo...">nz::graph</a></code> namespace is designed with performance in mind, utilizing CUDA to accelerate computation on GPUs.</p>
<dl class="section note"><dt>Note</dt><dd>The components in this namespace rely on CUDA for GPU-based operations. Ensure that CUDA-compatible hardware and software are properly configured.</dd></dl>
<dl class="section author"><dt>Author</dt><dd>Mgepahmge(<a href="https://github.com/Mgepahmge">https://github.com/Mgepahmge</a>)</dd></dl>
<dl class="section date"><dt>Date</dt><dd>2024/11/29 </dd></dl>
</div><h2 class="groupheader">Function Documentation</h2>
<a id="a3c6187d695022b05df227d913ac89d91" name="a3c6187d695022b05df227d913ac89d91"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a3c6187d695022b05df227d913ac89d91">&#9670;&#160;</a></span>CreateNode()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void nz::graph::CreateNode </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="classnz_1_1graph_1_1_compute_graph.html">ComputeGraph</a> *</td>          <td class="paramname"><span class="paramname"><em>graph</em></span>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const std::string &amp;</td>          <td class="paramname"><span class="paramname"><em>type</em></span>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const std::string &amp;</td>          <td class="paramname"><span class="paramname"><em>name</em></span>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">std::vector&lt; int &gt;</td>          <td class="paramname"><span class="paramname"><em>pre</em></span>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const <a class="el" href="classnz_1_1data_1_1_dimension.html">Tensor::shape_type</a> &amp;</td>          <td class="paramname"><span class="paramname"><em>shape</em></span>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">float *</td>          <td class="paramname"><span class="paramname"><em>data</em></span>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const bool</td>          <td class="paramname"><span class="paramname"><em>requires_grad</em></span>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">float *</td>          <td class="paramname"><span class="paramname"><em>grad</em></span>&#160;)</td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Creates and adds a node to the computational graph based on the specified type. </p>
<p>This function is used to create various types of nodes in a computational graph based on the provided node type, and then adds the created node to the <code><a class="el" href="classnz_1_1graph_1_1_compute_graph.html" title="Represents a computational graph, which manages nodes and the computation flow.">ComputeGraph</a></code> object. The node is initialized with the specified shape, data, and gradient information if needed. It also ensures that the nodes are connected to their previous nodes as specified by the <code>pre</code> vector.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">graph</td><td>The <code><a class="el" href="classnz_1_1graph_1_1_compute_graph.html" title="Represents a computational graph, which manages nodes and the computation flow.">ComputeGraph</a></code> object to which the new node will be added. </td></tr>
    <tr><td class="paramname">type</td><td>A string representing the type of node to be created. Supported types include "Input", "Output", "Add", "MatMul", "Sub", "ReLU", "Sigmoid", "Tanh", "LeakyReLU", "Swish", "ELU", "HardSigmoid", "HardSwish", "Softmax", "MeanSquaredError", "BinaryCrossEntropy". </td></tr>
    <tr><td class="paramname">name</td><td>The name of the node to be added to the graph. </td></tr>
    <tr><td class="paramname">pre</td><td>A vector of integers specifying the indices of the previous nodes (input nodes) that this node depends on. The number of elements in <code>pre</code> and the type of node may vary. </td></tr>
    <tr><td class="paramname">shape</td><td>A vector representing the shape of the node's output tensor. </td></tr>
    <tr><td class="paramname">data</td><td>A pointer to the data to initialize the node's output tensor. </td></tr>
    <tr><td class="paramname">requires_grad</td><td>A boolean flag indicating whether the node requires gradients for backpropagation. </td></tr>
    <tr><td class="paramname">grad</td><td>A pointer to the gradient data for the node's output tensor if <code>requires_grad</code> is true.</td></tr>
  </table>
  </dd>
</dl>
<dl class="exception"><dt>Exceptions</dt><dd>
  <table class="exception">
    <tr><td class="paramname">std::runtime_error</td><td>If an unsupported node type is provided or if there is a mismatch in node dependencies.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section note"><dt>Note</dt><dd><ul>
<li>The <code>CreateNode</code> function automatically handles the creation of nodes, their connection to previous nodes, and the addition of the new node to the graph.</li>
<li>The <code>pre</code> vector is used to specify which nodes are required as inputs for the current node, and it may differ in size based on the node type.</li>
<li>Some node types, such as "ScalarMul", "ScalarDiv", "ScalarAdd", and "ScalarSub", are not supported and will throw a runtime error.</li>
</ul>
</dd></dl>
<h3><a class="anchor" id="autotoc_md131"></a>
Usage Example:</h3>
<div class="fragment"><div class="line"><a class="code hl_class" href="classnz_1_1graph_1_1_compute_graph.html">ComputeGraph</a> graph;</div>
<div class="line">std::vector&lt;int&gt; pre = {0, 1};  <span class="comment">// Specify the input nodes for the current node</span></div>
<div class="line">std::vector&lt;int&gt; shape = {3, 3};  <span class="comment">// Specify the shape of the output tensor</span></div>
<div class="line"><span class="keywordtype">float</span> data[] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f};  <span class="comment">// Example data</span></div>
<div class="line"><a class="code hl_function" href="#a3c6187d695022b05df227d913ac89d91">CreateNode</a>(&amp;graph, <span class="stringliteral">&quot;Add&quot;</span>, <span class="stringliteral">&quot;add_node&quot;</span>, pre, shape, data, <span class="keyword">true</span>, <span class="keyword">nullptr</span>);  <span class="comment">// Create an &quot;Add&quot; node</span></div>
<div class="ttc" id="aclassnz_1_1graph_1_1_compute_graph_html"><div class="ttname"><a href="classnz_1_1graph_1_1_compute_graph.html">nz::graph::ComputeGraph</a></div><div class="ttdoc">Represents a computational graph, which manages nodes and the computation flow.</div><div class="ttdef"><b>Definition</b> <a href="_compute_graph_8cuh_source.html#l00224">ComputeGraph.cuh:224</a></div></div>
<div class="ttc" id="anamespacenz_1_1graph_html_a3c6187d695022b05df227d913ac89d91"><div class="ttname"><a href="#a3c6187d695022b05df227d913ac89d91">nz::graph::CreateNode</a></div><div class="ttdeci">void CreateNode(ComputeGraph *graph, const std::string &amp;type, const std::string &amp;name, std::vector&lt; int &gt; pre, const Tensor::shape_type &amp;shape, float *data, const bool requires_grad, float *grad)</div><div class="ttdoc">Creates and adds a node to the computational graph based on the specified type.</div><div class="ttdef"><b>Definition</b> <a href="_compute_graph_8cu_source.html#l00108">ComputeGraph.cu:108</a></div></div>
</div><!-- fragment --><dl class="section see"><dt>See also</dt><dd><a class="el" href="classnz_1_1graph_1_1_compute_graph.html" title="Represents a computational graph, which manages nodes and the computation flow.">ComputeGraph</a> for more details on <a class="el" href="namespacenz_1_1graph.html" title="Contains classes and functions for managing and executing computation graphs in deep learning workflo...">graph</a> structure and node management. </dd>
<dd>
<a class="el" href="classnz_1_1nodes_1_1_node.html" title="Base class for nodes in a neural network or computational graph.">nodes::Node</a> for information on individual node types and their operations.</dd></dl>
<dl class="section author"><dt>Author</dt><dd>Mgepahmge (<a href="https://github.com/Mgepahmge">https://github.com/Mgepahmge</a>)</dd></dl>
<dl class="section date"><dt>Date</dt><dd>2024/12/09 </dd></dl>

<p class="definition">Definition at line <a class="el" href="_compute_graph_8cu_source.html#l00108">108</a> of file <a class="el" href="_compute_graph_8cu_source.html">ComputeGraph.cu</a>.</p>

</div>
</div>
<a id="ae69fc8042f6dedeff293ab270f9c2baa" name="ae69fc8042f6dedeff293ab270f9c2baa"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ae69fc8042f6dedeff293ab270f9c2baa">&#9670;&#160;</a></span>operator&lt;&lt;()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">std::ostream &amp; nz::graph::operator&lt;&lt; </td>
          <td>(</td>
          <td class="paramtype">std::ostream &amp;</td>          <td class="paramname"><span class="paramname"><em>os</em></span>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="classnz_1_1graph_1_1_compute_graph.html">ComputeGraph</a> &amp;</td>          <td class="paramname"><span class="paramname"><em>graph</em></span>&#160;)</td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Overloads the stream insertion operator to print the details of the computational graph. </p>
<p>This function overloads the <code>&lt;&lt;</code> operator to provide an easy and intuitive way to print the details of a <code><a class="el" href="classnz_1_1graph_1_1_compute_graph.html" title="Represents a computational graph, which manages nodes and the computation flow.">ComputeGraph</a></code> object. It calls the <code>print</code> method of <code><a class="el" href="classnz_1_1graph_1_1_compute_graph.html" title="Represents a computational graph, which manages nodes and the computation flow.">ComputeGraph</a></code> to output the graph's nodes, their connections, data, gradients, and loss to the provided output stream.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">os</td><td>The output stream to which the graph details will be printed (e.g., <code>std::cout</code>). </td></tr>
    <tr><td class="paramname">graph</td><td>The <code><a class="el" href="classnz_1_1graph_1_1_compute_graph.html" title="Represents a computational graph, which manages nodes and the computation flow.">ComputeGraph</a></code> object whose details will be printed. </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>The output stream after printing the graph details, enabling method chaining.</dd></dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classnz_1_1graph_1_1_compute_graph.html#a1d54fe96c53fec967c8a20e1ac79ceed" title="Prints the details of the computational graph to the provided output stream.">ComputeGraph::print()</a> for more information about the internal printing process.</dd></dl>
<dl class="section author"><dt>Author</dt><dd>Mgepahmge (<a href="https://github.com/Mgepahmge">https://github.com/Mgepahmge</a>)</dd></dl>
<dl class="section date"><dt>Date</dt><dd>2024/12/09 </dd></dl>

<p class="definition">Definition at line <a class="el" href="_compute_graph_8cu_source.html#l00056">56</a> of file <a class="el" href="_compute_graph_8cu_source.html">ComputeGraph.cu</a>.</p>

</div>
</div>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.12.0
</small></address>
</div><!-- doc-content -->
</body>
</html>
